package faw.car.ccentersdk.prop;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;

/**
 * @Author zhuima
 */
public class MultiResponseBody implements Parcelable {

    private ArrayList<HQCarPropertyValue> dataList;

    public ArrayList<HQCarPropertyValue> getDataList() {
        return dataList;
    }

    public void setDataList(ArrayList<HQCarPropertyValue> dataList) {
        this.dataList = dataList;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (dataList != null && !dataList.isEmpty()) {
            dest.writeInt(dataList.size());
            for (HQCarPropertyValue hqCarPropertyValue : dataList) {
                hqCarPropertyValue.writeToParcel(dest, flags);
            }
        } else {
            dest.writeInt(0);
        }
    }

    public MultiResponseBody() {
    }

    protected MultiResponseBody(Parcel in) {

        int size = in.readInt();
        if (size > 0) {
            dataList = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                HQCarPropertyValue value = new HQCarPropertyValue();
                value.readFromParcel(in);
                dataList.add(value);
            }
        }
    }

    public static final Creator<MultiResponseBody> CREATOR = new Creator<MultiResponseBody>() {
        @Override
        public MultiResponseBody createFromParcel(Parcel source) {
            return new MultiResponseBody(source);
        }

        @Override
        public MultiResponseBody[] newArray(int size) {
            return new MultiResponseBody[size];
        }
    };
}
